package cn.iocoder.yudao.module.shop.framework.core.databind;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.util.Arrays;

public class WeekStringSerializer extends JsonSerializer<String> {

    /**
     * 序列化
     */
    @Override
    public void serialize(String s, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        String resultS = "";
        final String[] originNum = {"1","2","3","4","5","6","7"};
        final String[] formatNum = {"一","二","三","四","五","六","日"};

        if (StringUtils.isNotBlank(s)) {
            Arrays.sort(originNum);

            int index = Arrays.binarySearch(originNum,s);
            if (index>=0){
                resultS =  formatNum[index];
            }else{
                resultS =  "错误的值类型";
            }
        }else{
            resultS =  "错误的值类型";
        }
        jsonGenerator.writeString(resultS);
    }
}
